word文件批注替换和查找替换
//批注替换
private void button1_Click(object sender, EventArgs e)
{
string oldstr = textBox1.Text;
string newstr = textBox2.Text;
string filepath = "";//模板地址
string savepath = "";//保存地址
try
{
filepath = System.Windows.Forms.Application.StartupPath.ToString() "\\文件\\批注替换.doc";
savepath = System.Windows.Forms.Application.StartupPath.ToString() "\\文件\\NEW_批注替换.doc";
bool ret =replace_by_comments(oldstr,newstr,filepath, savepath);//导出文件
if (ret)
{
MessageBox.Show("成功导出证书并上传!", "提示", MessageBoxButtons.OK);
}
else
{
MessageBox.Show("导出上传证书失败", "提示", MessageBoxButtons.OK);
}
}
catch (Exception ex)
{
MessageBox.Show("导出数据异常!异常描述:" ex.Message, "提示", MessageBoxButtons.OK);
}
}
//查找替换
private void button2_Click(object sender, EventArgs e)
{
string oldstr = textBox1.Text;
string newstr = textBox2.Text;
string filepath = "";//文件地址
filepath = System.Windows.Forms.Application.StartupPath.ToString() "\\文件\\批注替换.doc";
WordReplacexia(filepath, oldstr, newstr);
}
评论